package com.ruoyi.DataManage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.DataManage.domain.Province;
import com.ruoyi.DataManage.domain.Subject_tree;
import com.ruoyi.DataManage.domain.University;
import com.ruoyi.DataManage.service.ISubject_treeService;
import com.ruoyi.DataManage.service.IUniversityService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.DataManage.domain.ExaminationCourse;
import com.ruoyi.DataManage.service.IExaminationCourseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考试科目管理Controller
 * 
 * @author CehnFneg
 * @date 2024-04-23
 */
@RestController
@RequestMapping("/DataManage/examination_course")
public class ExaminationCourseController extends BaseController
{
    @Autowired
    private IExaminationCourseService examinationCourseService;

    @Autowired
    private IUniversityService universityService;

    @Autowired
    private ISubject_treeService subject_treeService;

    /**
     * 查询考试科目管理列表
     */
    @PreAuthorize("@ss.hasPermi('DataManage:examination_course:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExaminationCourse examinationCourse)
    {
        startPage();
        List<ExaminationCourse> list = examinationCourseService.selectExaminationCourseList(examinationCourse);
        return getDataTable(list);
    }

    /**
     * 导出考试科目管理列表
     */
    @PreAuthorize("@ss.hasPermi('DataManage:examination_course:export')")
    @Log(title = "考试科目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExaminationCourse examinationCourse)
    {
        List<ExaminationCourse> list = examinationCourseService.selectExaminationCourseList(examinationCourse);
        ExcelUtil<ExaminationCourse> util = new ExcelUtil<ExaminationCourse>(ExaminationCourse.class);
        util.exportExcel(response, list, "考试科目管理数据");
    }

    /**
     * 获取考试科目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('DataManage:examination_course:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(examinationCourseService.selectExaminationCourseById(id));
    }

    /**
     * 新增考试科目管理
     */
    @PreAuthorize("@ss.hasPermi('DataManage:examination_course:add')")
    @Log(title = "考试科目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExaminationCourse examinationCourse)
    {
        return toAjax(examinationCourseService.insertExaminationCourse(examinationCourse));
    }

    /**
     * 修改考试科目管理
     */
    @PreAuthorize("@ss.hasPermi('DataManage:examination_course:edit')")
    @Log(title = "考试科目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExaminationCourse examinationCourse)
    {
        return toAjax(examinationCourseService.updateExaminationCourse(examinationCourse));
    }

    /**
     * 删除考试科目管理
     */
    @PreAuthorize("@ss.hasPermi('DataManage:examination_course:remove')")
    @Log(title = "考试科目管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(examinationCourseService.deleteExaminationCourseByIds(ids));
    }

    @GetMapping("/universitylist")
    public AjaxResult universityList()
    {
        List<University> universityList = universityService.getUniversityList();
        return AjaxResult.success(universityList);
    }

    @GetMapping("/majorlist/{universityId}")
    public AjaxResult majorList(@PathVariable Long universityId)
    {
        List<Subject_tree> majorList = subject_treeService.getMajorList(universityId);
        return AjaxResult.success(majorList);
    }
}
